function computed(h1, h2, type) {
    let
        alpha_i = 360.57125891724,
        alpha_w = 8528,
        alpha_tp = 260.52967322633,
        mr = 1,
        Trm = 44,
        Twm = 38.5,
        pi = 3.14159,
        di = 0.02,
        d0 = 0.025;
    return type = 'w' ?
        (1 / alpha_i + 1 / alpha_w * (di / d0)) * mr * (h1 - h2) / ((Trm - Twm) * pi * di)
        :
        (1 / alpha_i + 1 / alpha_tp * (di / d0)) * mr * (h1 - h2) / ((Trm - Twm) * pi * di);
}

function clac(hl, hg, L, hcrl, hcrg, hcri) {
    let l_real = 0;
    let hcro = 0;
    while (Math.abs(l_real - L) > 0.001) {
        let current_h = (hl + hg) / 2;
        let Lsc = 0,
            Ltp = 0,
            Lsh = 0;
        if (current_h < hcrl) {
            Lsc = computed(hcrl, current_h, 'w');
            Ltp = computed(hcrg, hcrl, 'tp');
        } else {
            Ltp = computed(hcrg, current_h, 'tp');
        }
        Lsh = computed(hcri, hcrg, 'w');
        l_real = Lsc + Ltp + Lsh;
        if (l_real - L > 0.001) {
            hl = current_h
        } else if (l_real - L < -0.001) {
            hg = current_h
        } else {
            hcro = currentQ
            break;
        }
    }
    return final_q;
}
// debugger;
console.log(clac(250273.538976, 420957.58771647, 900, 262223.59617822, 420957, 442206)
)